//
//  CAnAlgAutoDetecActivity.m
//  sr01sdkProject
//
//  Created by  on 2024/9/2.
//  活动自检数据

#import "CAnAlgAutoDetecActivity.h"

@implementation CAnAlgAutoDetecActivity
-(NSNumber *)dataTimeStamp
{
    return @(self.timeStamp);
}
- (instancetype)initWithData:(NSData *)data
{
    self = [super init];
    if (self) {
        
        if (data.length < 20) {
            return self;
        }
        
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        _cmdByte = dataBytes[1];
        // 四字节时间戳
        uint32_t timeStamp = *((uint32_t *)(dataBytes + 2));
        _timeStamp = timeStamp;
        
        uint32_t uuid = (dataBytes[8]<< 16) +(dataBytes[7]<< 8) +dataBytes[6];
        _dataUuid = @(uuid);
        _distance = dataBytes[9] /10.0f;
        
        _steps =  *( (uint16_t *)(dataBytes + 10) );
        _wholeEnergyCnsmptn =  *( (uint16_t *)(dataBytes + 12) );
        _activityEnergyCnsmptn =  *( (uint16_t *)(dataBytes + 14) );
        
        uint8_t vo2 = dataBytes[16] & 0xFF;
        if (vo2 != 0XFF) {
            _vo2 = @(vo2);
        }
        
        uint8_t vo2Max =  dataBytes[17] & 0xFF;
        if (vo2Max != 0XFF) {
            _vo2Max = @(vo2Max);
        }
        uint8_t status = dataBytes[18];
        _activityType = status & 0x07;
         
        _keepExeType = (status >> 3) & 0x01;

    }
    return self;
}

@end
